﻿using System;
using System.Collections.Generic;
using Mads.CoreDomain.Enumerations;
using System.Runtime.Serialization;

namespace Mads.CoreDomain
{
  [DataContract]
  public class User : KeyAbstraction
  {
    #region public properties
    /// <summary>
    /// User login. User uses his login to log in.
    /// </summary>
    [DataMember]
    public string Login { get; private set; }

    /// <summary>
    /// Saved hash of user password.
    /// </summary>
    [DataMember]
    public string PasswordHash { get; set; }

    /// <summary>
    /// Email address of this user.
    /// </summary>
    [DataMember]
    public string Email {get; set;}

    /// <summary>
    /// User privileges in the system.
    /// </summary>
    [DataMember]
    public UserRole Role { get; set; }

    /// <summary>
    /// Default values for user credentials as ticket owner.
    /// Not required.
    /// </summary>
    public TicketOwner DefaultInfo { get; set; }

    /// <summary>
    /// Orders commited by this user.
    /// </summary>
    public IEnumerable<Order> Orders { get; private set; }
    #endregion

    public User(string login, string passwordHash, string email,
      UserRole role, TicketOwner defaultInfo)
    {
      if (String.IsNullOrEmpty(login))
      {
        throw new ArgumentException("login");
      }
      if (String.IsNullOrEmpty(passwordHash))
      {
        throw new ArgumentException("passwordHash");
      }
      if (email == null)
      {
        throw new ArgumentNullException("email");
      }

      Login = login;
      PasswordHash = passwordHash;
      Email = email;
      Role = role;
      DefaultInfo = defaultInfo;
    }
    public User(string login, string passwordHash,
      string email, UserRole role)
      : this(login, passwordHash, email, role, null)
    {
    }
  }
}